<template>
  <div>
    <el-table :data="resList" border style="width: 100%">
      <el-table-column prop="uid" label="id" width="180"> </el-table-column>
      <el-table-column prop="nickname" label="姓名" width="180">
      </el-table-column>
      <el-table-column label="头像" width="180">
        <template slot-scope="scope">
          <img :src="scope.row.avatar" alt="" width="40px" height="40px" />
        </template>
      </el-table-column>
      <el-table-column prop="mobile" label="手机号" width="180">
      </el-table-column>
      <el-table-column label="创建时间" width="180">
        <template slot-scope="scope">{{
          scope.row.created_at | filtime
        }}</template>
        <!-- 插槽 如果有些内容不是直接展示的而是要经过处理 插槽中的scope.row代表这一行数据 -->
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle  @click="BJ(scope.row)"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle @click="remove(scope,index)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="list.length"
      :current-page="pageNum"
      :page-size="pageSize"
      @current-change="changepage"
    >
    </el-pagination>

    <!-- 弹出框 -->
    
<el-dialog title="修改信息" :visible.sync="tankuang">
  <el-form :model="form">
    <el-form-item label="用户名" >
      <el-input v-model="form.name" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="手机号" >
      <el-input v-model="form.mobile" autocomplete="off"></el-input>
    </el-form-item>
   
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="XG">确 定</el-button>
  </div>
</el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      list: [],
      pageSize: 7,
      pageNum: 1,
      form:{
          name:'',
          mobile:'',
          uid:''
      },
      tankuang:false
    };
  },
  mounted() {
    this.$axios("/list.json").then((res) => {
      console.log(res);
      this.list = res.data;
    });
  },
  filters: {
    filtime(val) {
      return new Date(val * 1000).toLocaleString();
    },
  },
  methods: {
    changepage(val) {
      console.log(val);
      this.pageNum = val;
    },
    remove(index){
        this.list.splice(index,1)
    },
    BJ(val){
        this.tankuang=true
        this.uid=val.uid
        this.form.name=val.nickname
        this.form.mobile=val.mobile
    },
    XG(){
        this.tankuang=false
        this.list.forEach(item => {
            if(item.uid==this.uid){
                item.nickname=this.form.name
                item.mobile=this.form.mobile
            }
        });
    }
  },
  computed: {
    resList() {
      return this.list.slice(
        this.pageSize * (this.pageNum - 1),
        this.pageSize * this.pageNum
      );
    },
  },
};
</script>